package com.by;

import com.by.config.DbConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

public class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * spring根配置类 注解扫描入口
     * @return
     */
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{DbConfig.class};
    }

    protected Class<?>[] getServletConfigClasses() {
        return new Class[0];
    }

    /**
     * 拦截映射路径
     * @return
     */
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

//    /**
//     * 配置文件拦截器（文件上传时必须存在）
//     * @return
//     */
//    @Override
//    protected Filter[] getServletFilters() {
//        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
//        encodingFilter.setEncoding("UTF-8");
//        encodingFilter.setForceRequestEncoding(true);
//        HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
//        return new Filter[]{encodingFilter, hiddenHttpMethodFilter};
//    }
//注册文件上传
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
    registration.setMultipartConfig(new MultipartConfigElement(""));

}
}
